package org.xx.armory.db;

import java.util.Collection;
import java.util.EnumSet;
import java.util.Set;

import static org.xx.armory.commons.Validators.notBlank;

final class MockParameter
        implements Parameter {
    private static final Set<ParameterDirection> IN = EnumSet.of(ParameterDirection.IN);
    @SuppressWarnings("unused")
    private static final Set<ParameterDirection> OUT = EnumSet.of(ParameterDirection.OUT);
    @SuppressWarnings("unused")
    private static final Set<ParameterDirection> IN_OUT = EnumSet.of(ParameterDirection.IN, ParameterDirection.IN);
    private final String name;
    private final ParameterType parameterType;
    private final Set<ParameterDirection> directions;
    private final Object value;

    private MockParameter(
            String name,
            ParameterType parameterType,
            Collection<ParameterDirection> directions,
            Object value
    ) {
        this.name = notBlank(name, "name").trim();
        this.parameterType = parameterType;
        this.directions = EnumSet.copyOf(directions);
        this.value = value;
    }

    public static Parameter create(
            String name,
            ParameterType parameterType,
            Object value
    ) {
        return new MockParameter(name, parameterType, IN, value);
    }

    @Override
    public String getName() {
        return this.name;
    }

    @Override
    public ParameterType getParameterType() {
        return this.parameterType;
    }

    @Override
    public Set<ParameterDirection> getDirections() {
        return this.directions;
    }

    @Override
    public Object getValue() {
        return this.value;
    }

    @Override
    public void setValue(Object value) {
        throw new UnsupportedOperationException();
    }

    @Override
    public boolean isNull() {
        return this.value == null;
    }

    @Override
    public boolean isEmpty() {
        return this.value == null || this.value.toString().isEmpty();
    }
}
